# Create your views here.
# -*- coding: utf-8 -*-

from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.utils.translation import ugettext_lazy as _

from goplay.sinaweibo.message import messages
from goplay.sinaweibo.update import update
from forms import sendMessagesForm



def sendMessages(request): 
    form=sendMessagesForm()  
    if request.method=="POST":    
        form=sendMessagesForm(request.POST.copy())
        if form.is_valid():          
            access_token=request.session['oauth_access_token']
            username=form.cleaned_data['user']
            content=form.cleaned_data['content']
            messages().send(access_token.key,access_token.secret, username, content)
        else:
            return HttpResponseRedirect(reverse('index'))
    return HttpResponseRedirect(reverse('index'))

def updateWeibo(request,date,activityName):
    date=date.encode('utf-8')
    activityName=activityName.encode('utf-8')
    if date=='2008-03-08':
        content=ur'我最近想要'+activityName+ur'。谁有兴趣啊～～～'
        #content=activityName
    else:
        content=ur'我'+date+u'要'+activityName+ur'。感兴趣的一起来啊～～'
        #content=activityName
    access_token=request.session['oauth_access_token']
    update().send(access_token.key,access_token.secret,content)
    return 'successfully'
        
    
